<!-- 库区设置 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog"  v-bind="dialog" @afterSubmitSuccess="submitAfter">
    </ex_super_dialog_form>

    <dialog_detail_desc ref="dialog_detail_desc" url="/wms-api/base/WmsBaseAreaRpc/detail.json"
      :descOption="descOption" />
    <!-- <detail_area ref="detail_area"></detail_area> -->
    <print_sku ref="print_sku" itemKey="id" businessType="AREA" />

  </div>
</template>
<script>
import print_sku from '@/component/print/print_sku'

// import common_print_dialog from '@/component/print/common_print_dialog'

import superTablePageFunction from '@/mixin/super-table-page-function';
// import Detail_area from "@/component/dialog/wms_base/detail_area.vue";
export default {
  title: 'title_Warehouse_area_manage',
  mixins: [superTablePageFunction],
  components: { print_sku, },
  data() {
    return {
      selection: [],

      option: {
        search: {
          model: [
            { label: "label_warehouse_area_code", key: "code", type: 'input', },
            { label: "label_warehouse_area_name", key: "name", type: 'input', },
            {
              label: "label_type", key: "type", type: 'select', enum: 'BaseAreaTypeEnum',
            },
            {
              label: "label_status", key: "status", type: 'select', enum: 'IsAvailableStatusEnum',
            },

            {
              label: "label_start_time",
              key: "createDateStart",
              fold: true,
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "label_end_time",
              key: "createDateEnd",
              fold: true,
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
          ],
        },
        action: [
          {
            label: 'label_new_warehouse_area', auth: 'wms_area_setting_edit', attrs: { icon: "el-icon-plus" }, click: () => {
              this['$refs']['formDialog'].showNew({
                title: this.$tt('label_new_warehouse_area'),
                data: {},
                onlySetData: true,
              })
            }
          },
        ],
        actionExtra: [
          {
            label: 'label_print_barcode', attrs: { type: "primary" }, click: (row) => {
              if (_.isEmpty(this.selection)) {
                return this.$message.error(this.$tt('tip_please_select_order'))
              }
              this.print(this.selection)
            }
          },
        ],
        table: {
          url: "/wms-api/base/WmsBaseAreaRpc/selectPage.json",
          attrs: {},
          model: [
            { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },

            { key: 'code', label: 'label_warehouse_area_code', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'name', label: 'label_warehouse_area_name', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'type', label: 'label_warehouse_area_type', 'min-width': 120, formatter: (r, c, v, i) => this.$enumShow(v, "BaseAreaTypeEnum") },
            { key: 'status', label: 'label_status', 'min-width': 120, formatter: (r, c, v, i) => this.$enumShow(v, "IsAvailableStatusEnum") },
            { key: 'warehouseName', label: 'label_warehouse_name', 'min-width': 150, 'show-overflow-tooltip': true, },
            { key: 'alleyNum', label: 'label_tunnel_count', 'min-width': 60, 'show-overflow-tooltip': true, },
            { key: 'attribute', label: 'label_warehouse_area_attr', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'useType', label: 'label_warehouse_area_usage', 'min-width': 80, formatter: (r, c, v, i) => this.$enumShow(v, "BaseAreaUsageTypeEnum") },
            { key: 'maxBoxNum', label: 'label_maximum_number_boxes', 'min-width': 60, 'show-overflow-tooltip': true, },
            { key: 'maxBoardNum', label: 'label_minimum_number_pallet', 'min-width': 60, 'show-overflow-tooltip': true, },
            { key: 'creator', label: 'label_create_user', 'min-width': 60, 'show-overflow-tooltip': true, },
            { key: 'gmtCreate', label: 'label_create_time', 'min-width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v) },
            {
              type: 'operate', width: 210, operate: [
                {
                  label: 'label_edit', auth: 'wms_area_setting_edit', click: (row) => {
                    this['$refs']['formDialog'].showNew({
                      title: this.$tt('label_edit_warehouse_area'),
                      params: { "id": row["id"] },
                    })
                  }
                },
                {
                  label: 'label_delete', auth: 'wms_area_setting_delete', type: "confirm-button", url: '/wms-api/base/WmsBaseAreaRpc/remove.json', message: 'label_fms_bank_card_confirm_delete',
                  buttonClass: "button_text_danger", confirmButtonType: 'danger',
                  params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
                },
                {
                  type: 'more',
                  items: [
                    { label: "label_print_barcode", click: (row) => this.print([row]) },
                    { label: 'label_view_detail', click: (row) => this.clickDetail(row) },
                  ]
                },
              ]
            },
          ],
          // operate: [
          //
          //
          // ],
        },
      },

      dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/wms-api/base/WmsBaseAreaRpc/saveUpdate.json',
        detailUrl: '/wms-api/base/WmsBaseAreaRpc/detail.json',
        form: {
          itemClass: "form_item_mini", inputClass: "form_input_small",
          formClass: "form_mini_col2 ",
          inline: true,
          model: [
            { header: "label_base_info", },
            { key: 'code', label: 'label_warehouse_area_code', disabled: (data) => !_.isEmpty(data.id) },
            { key: 'name', label: 'label_warehouse_area_name', },
            { key: 'nameEn', label: 'label_warehouse_area_english_name', },

            { key: 'type', label: 'label_warehouse_area_type', type: 'select', enum: 'BaseAreaTypeEnum' },
            { key: 'useType', label: 'label_warehouse_area_usage', type: 'select', enum: 'BaseAreaUsageTypeEnum' },
            { key: 'takedownMode', label: 'label_pick_down_method', type: 'select', enum: 'BaseTakedownModeEnum' },

            { key: 'maxBoxNum', label: 'label_maximum_number_boxes', },
            { key: 'maxBoardNum', label: 'label_minimum_number_pallet', },
            { key: 'floor', label: 'label_floor', },
            { key: 'mixFlag', label: 'label_is_mixed_load', type: 'select', enum: 'YesOrNoEnum' },
            { key: 'attribute', label: 'label_warehouse_area_attr', },
            { key: 'baseRemark', label: 'label_remark', },
            {
              label: "label_warehouse_area_mark",
              key: "tagCode",
              type: 'select',
              url: '/wms-api/base/WmsDictValueRpc/dictValue_front.json?type=WAREHOUSE_AREA_TAG',
              option: { label: 'label', value: 'value' }
            },

            { header: "label_business_rules", },
            { key: 'storageRatio', label: 'label_restriction_ratio', append: '%', appendClass: 'input_slot_div_mini' },
            { key: 'outboundRatio', label: 'label_plate_shipment_ratio', append: '%', appendClass: 'input_slot_div_mini' },
            { key: 'inboundLimitType', label: 'label_limit_inbound_type', type: 'select', enum: 'BaseLimitInboundTypeEnum' },
            { key: 'allowPick', label: 'label_allow_picking', type: 'select', enum: 'YesOrNoEnum' },
            { key: 'taskSort', label: 'label_picking_order', },
            { key: 'businessRemark', label: 'label_remark', },
            {
              key: 'newSkuInboundStorageRatio', label: 'label_new_sku_storage_ratio', type: 'select',
              attrs: {
                items: [
                  { label: '10%', value: 10 }, { label: '30%', value: 30 },
                  { label: '50%', value: 50 }, { label: '80%', value: 80 },
                ],
              },
            },
            {
              grid: [
                [
                  {
                    span: 12, col: {
                      key: 'safetyStockRule', label: 'label_safety_stock_setting', type: 'select',
                      attrs: {
                        enum: 'WmsSafeStockRuleTypeEnum',
                      },
                    },
                  },
                  {
                    span: 12, col: {
                      key: 'safetyStockRatio', label: 'label_setting_value', type: 'select', if: (data) => data.safetyStockRule === 'STOCK_RATIO',
                      inputClass: 'w_fill',
                      attrs: {
                        items: [
                          { label: '10%', value: 10 }, { label: '30%', value: 30 },
                          { label: '50%', value: 50 }, { label: '80%', value: 80 }
                        ],
                      },
                    },
                  },
                  {
                    span: 12, col: {
                      key: 'minSafetyStockNum', label: 'label_setting_value', type: 'el-input-number', if: (data) => data.safetyStockRule === 'SAFETY_NUM',
                      inputClass: 'w_fill',
                      attrs: {
                        'step-strictly': true, min: 0, max: 9999999,
                      },
                    },
                  },
                  {
                    span: 12, col: {
                      key: 'saleCycle', label: 'label_setting_value', type: 'select', if: (data) => data.safetyStockRule === 'SALE_CYCLE',
                      inputClass: 'w_fill',
                      attrs: {
                        enum: 'WmsSaleCycleEnum',
                      },
                    },
                  },
                ]
              ]
            },
          ],
          rules: {
            'code': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'name': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'type': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'status': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'floor': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
            'alleyNum': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' }],
            'mixFlag': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'maxBoxNum': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'maxBoardNum': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'useType': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'takedownMode': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
          },
        }
      },
      descOption: {
        model: [
          { key: 'code', label: 'label_warehouse_area_code' },
          { key: 'name', label: 'label_warehouse_area_name', },
          { key: 'nameEn', label: 'label_warehouse_area_english_name', },
          { key: 'type', label: 'label_warehouse_type', formatter: (r, c, v) => this.$enumShow(v, "BaseAreaTypeEnum") },
          { key: 'status', label: 'label_status', formatter: (r, c, v) => this.$enumShow(v, "IsAvailableStatusEnum") },
          { key: 'warehouseName', label: 'label_warehouse_name' },
          { key: 'alleyNum', label: 'label_tunnel_count', },
          { key: 'useType', label: 'label_warehouse_area_usage', formatter: (r, c, v) => this.$enumShow(v, "BaseAreaUsageTypeEnum") },
          { key: 'takedownMode', label: 'label_pick_down_method', formatter: (r, c, v) => this.$enumShow(v, "BaseTakedownModeEnum") },

          { key: 'maxBoxNum', label: 'label_maximum_number_boxes', },
          { key: 'maxBoardNum', label: 'label_minimum_number_pallet', },
          { key: 'floor', label: 'label_floor', },
          { key: 'mixFlag', label: 'label_is_mixed_load', formatter: (r, c, v) => this.$enumShow(v, "YesOrNoEnum") },
          { key: 'attribute', label: 'label_warehouse_area_attr', },
          { key: 'baseRemark', label: 'label_remark', },
          { key: 'creator', label: 'label_create_user', },
          { key: 'gmtCreate', label: 'label_create_time', formatter: (r, c, v, i) => this.$dateFormat(v) },

          { key: 'storageRatio', label: 'label_restriction_ratio', formatter: (r, c, v, i) => `${v}%` },
          { key: 'outboundRatio', label: 'label_plate_shipment_ratio', formatter: (r, c, v, i) => `${v}%` },
          {
            key: 'inboundLimitType',
            label: 'label_limit_inbound_type',
            formatter: (r, c, v) => this.$enumShow(v, "BaseLimitInboundTypeEnum")
          },
          { key: 'allowPick', label: 'label_allow_picking', formatter: (r, c, v) => this.$enumShow(v, "YesOrNoEnum") },
          { key: 'taskSort', label: 'label_picking_order', },
          { key: 'businessRemark', label: 'label_remark', },

        ],
      },
    };
  },
  methods: {
    print(rows) {
      this.$refs.print_sku.show(rows)
    },
    submitAfter() {
      this.reload()
      this.$refreshStoreCommonDataGroup('/wms-api/base/WmsBaseAreaRpc/selectAllLabel.json')
    },
    clickDetail(row) {
      let title = this.$formatNameCode(this.$tt('label_warehouse_area_detail'), row.code)
      this.$refs['dialog_detail_desc'].show({ params: { id: row.id }, title })
    },
  }
};

</script>
<style></style>
